<?php
/**
 * Created by JetBrains PhpStorm.
 * User: thuann89
 * Date: 7/7/12
 * Time: 1:05 PM
 * To change this template use File | Settings | File Templates.
 */
class NewProductsWidget extends CWidget
{
    public $title='';
    public $numOfItems=3;
    public $emptyText='';

    public function run()
    {
        $criteria = new CDbCriteria();
        $criteria->with = array(
            'localeProduct' => array(
                'condition' => 'locale=:locale',
                'params' => array(':locale' => Yii::app()->language)
            ),
        );
        $criteria->compare('t.status', Product::STATUS_ACTIVE);
        $criteria->order = 't.create_time DESC, t.id DESC';
        $criteria->limit = $this->numOfItems;
        $models = Product::model()->findAll($criteria);    
        $products_by_cats = array();
        foreach($models as $model)
        {
            $products_by_cats[$model->category_id][] = $model;
        }
        unset($models);
        $this->render('new-product',array('products_by_cats'=>$products_by_cats));
    }
}
